import { sleep } from '../../services/utils'
import { Project } from '../../pages/aides-projects/types'
import aidesProjectsDb from './aides-projects.json'

export type Pagination = {
  page: number
  perPage: number
  total: number
}

export type Sorting = {
  sortBy: keyof Project | undefined
  sortingOrder: 'asc' | 'desc' | null
}

export type Filters = {
  isActive: boolean
  search: string
}

export const getProjects = async (filters: Partial<Filters & Pagination & Sorting>) => {
  await sleep(1000)
  const projects = aidesProjectsDb as Project[]
  const { page = 1, perPage = 10 } = filters || {}
  return {
    data: projects.slice((page - 1) * perPage, page * perPage),
    pagination: {
      page,
      perPage,
      total: projects.length,
    },
  }
}

export const addProject = async (project: Project) => {
  await sleep(1000)
  console.log(project)
}

export const updateProject = async (project: Project) => {
  await sleep(1000)
  console.log(project)
}

export const removeProject = async (project: Project) => {
  await sleep(1000)
  console.log(project)
}
